package com.lagou.service.impl;

import com.lagou.base.StatusCode;
import com.lagou.dao.CourseLessonDao;
import com.lagou.dao.impl.CourseLessonDaoImpl;
import com.lagou.pojo.Course_Lesson;
import com.lagou.service.CourseLessonService;
import com.lagou.utils.DateUtils;

public class CourseLessonServiceImpl implements CourseLessonService {
    CourseLessonDao courseLessonDao = new CourseLessonDaoImpl();

    @Override
    public String saveCourseLesson(Course_Lesson lesson) {
        String date = DateUtils.getDateFormart();
        lesson.setCreate_time(date);
        lesson.setUpdate_time(date);
        lesson.setStatus(2);
        int row = courseLessonDao.saveCourseLesson(lesson);
        //3.根据是否插入成功,封装对应信息
        if(row > 0){
            //保存成功
            String result = StatusCode.SUCCESS.toString();
            return result;
        }else{
            String result = StatusCode.FAIL.toString();
            return result;
        }
    }

    @Override
    public String updateCourseLesson(Course_Lesson course_lesson) {
        //1.补全信息
        String date = DateUtils.getDateFormart();
        course_lesson.setUpdate_time(date);
        //2.调用dao
        int row = courseLessonDao.updateCourseLesson(course_lesson);
        //3.判断是否插入成功
        if(row > 0){
            String result = StatusCode.SUCCESS.toString();
            return result;
        }else{
            String result  = StatusCode.FAIL.toString();
            return result;
        }
    }
}
